﻿
Imports elpmis
Imports webctrl

Namespace lpmsservFunctions

    'parameters, page, optional, the xhtmlpage instance
    '            inlineScript, optional, the inlineScript of an xhtmlpage, overwrite page
    '            id, any, convert to string
    '            value, any
    'return, string, action link
    Public MustInherit Class jsoperateById
        Inherits internalFunction

        Class parameters
            Public Const page As String = "page"
            Public Const inlineScript As String = "inlineScript"
            Public Const id As String = "id"
            Public Const value As String = "value"
        End Class

        Protected Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub

        Protected MustOverride Overloads Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                             ByVal id As String, ByVal value As Object) As String

        Protected Overridable Function requireValue() As Boolean
            Return True
        End Function

        Protected NotOverridable Overrides Function invoke(ByVal ctx As context, _
                                                           ByRef output As bare_variable) As Boolean
            Dim id As String = Nothing
            If ctx.findVariableStr(parameters.id, id) Then
                Dim value As Object = Nothing
                If Not requireValue() OrElse ctx.findVariable(Of Object)(parameters.value, value) Then
                    Dim inlineScript As inlineScript = Nothing
                    getinlinescript(ctx, inlineScript, parameters.page, parameters.inlineScript)
                    output = New bare_variable(typeDefination.string, _
                                               invokeImpl(inlineScript, id, value))
                    Return True
                Else
                    raiseError("expect parameter " + parameters.value, errorHandle.errorType.user)
                    Return False
                End If
            Else
                raiseError("expect parameter " + parameters.id, errorHandle.errorType.user)
                Return False
            End If
        End Function
    End Class

    'parameters, same as jsoperateById
    'return, same as jsoperateById
    Public Class jschangeInnerHtmlById
        Inherits jsoperateById

        Public Sub New()
            MyBase.New("js.operate.id.innerHtml")
        End Sub

        Protected Overrides Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                ByVal id As String, ByVal value As Object) As String
            Return changeInnerHtmlById.invoke(inlineScript, id, value)
        End Function
    End Class

    'parameters, same as jsoperateById
    'return, same as jsoperateById
    Public Class jsvisibilityById
        Inherits jsoperateById

        Public Sub New()
            MyBase.New("js.operate.id.visibility")
        End Sub

        Protected Overrides Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                ByVal id As String, ByVal value As Object) As String
            Return visibilityById.invoke(inlineScript, id, Convert.ToString(value))
        End Function
    End Class

    'parameters, same as jsoperateById
    'return, same as jsoperateById
    Public Class jsshowById
        Inherits jsoperateById

        Public Sub New()
            MyBase.New("js.operate.id.show")
        End Sub

        Protected Overrides Function requireValue() As Boolean
            Return False
        End Function

        Protected Overrides Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                ByVal id As String, ByVal value As Object) As String
            Return showById.invoke(inlineScript, id)
        End Function
    End Class

    'parameters, same as jsoperateById
    'return, same as jsoperateById
    Public Class jshideById
        Inherits jsoperateById

        Public Sub New()
            MyBase.New("js.operate.id.hide")
        End Sub

        Protected Overrides Function invokeImpl(ByVal inlineScript As inlineScript, _
                                                ByVal id As String, ByVal value As Object) As String
            Return hideById.invoke(inlineScript, id)
        End Function
    End Class
End Namespace
